<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改资料</title>
    <link rel="stylesheet" type="text/css" href="/static/h+/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/font-awesome.min93e3.css?v=4.4.0">
    <!-- Data Tables -->
    <link rel="stylesheet" type="text/css" href="/static/h+/css/plugins/iCheck/custom.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/style.min.css?v=4.1.0">
    <link rel="stylesheet" type="text/css" href="/static/layer/skin/layer.css">
    <link rel="stylesheet" type="text/css" href="/static/uploadifive/uploadifive.css">
    <style type="text/css">
        .form-control{width: 200px;}
        #preview{max-width: 120px;max-height: 120px;}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
  <div class="row">
    <div class="col-sm-12">
      <div class="ibox float-e-margins">
        <div class="ibox-title">
          <h5>修改资料</h5>
        </div>
        <div class="ibox-content">
          <form class="form-horizontal" onsubmit="return false">
            <div class="form-group">
              <label class="col-sm-2 control-label">登录账号</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="username" value="{$user.username}"{if($user.username==='admin')} disabled="1"{/if}>
              </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
              <label class="col-sm-2 control-label">登录密码</label>
              <div class="col-sm-10">
                <input type="password" class="form-control" id="pwd1">
              </div>
            </div>
              <div class="hr-line-dashed"></div>
              <div class="form-group">
                <label class="col-sm-2 control-label">确认密码</label>
                <div class="col-sm-10">
                  <input type="password" class="form-control" id="pwd2">
                </div>
              </div>
              {if($user.username!=='admin')}
              <div class="hr-line-dashed"></div>
              <div class="form-group">
                <label class="col-sm-2 control-label">用户角色</label>
                <div class="col-sm-10">
                  <select id="role_id" class="form-control"{if(session('admin')['role_id']!==1)} disabled="1"{/if}>
                    <option value="0">…请选择用户角色…</option>
                    {foreach $roles as $r}
                    <option value="{$r.id}"{if($user.role_id==$r.id)} selected="selected"{/if}>{$r.role_name}</option>
                    {/foreach}
                </select>
              </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
              <label class="col-sm-2 control-label">状态</label>
              <div class="col-sm-10">
                <select id="status" class="form-control">
                    <option value="1" {if($user.status===1)}selected="selected"{/if}>正常</option>
                    <option value="4" {if($user.status===4)}selected="selected"{/if}>禁用</option>
                </select>
              </div>
            </div>{/if}
            <div class="hr-line-dashed"></div>
            <div class="form-group">
              <div class="col-sm-4 col-sm-offset-2">
                <input class="btn btn-primary" type="button" data-action="save" value="保存内容">
                {if($uname==='admin'||$uname==='royhe')}<input class="btn btn-white" type="button" data-action="cancel" value="取消">{/if}
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
<script type="text/javascript" src="/static/h+/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/h+/js/plugins/iCheck/icheck.min.js"></script>
<script type="text/javascript" src="/static/layer/layer.js"></script>
<script type="text/javascript" src="/static/uploadifive/jquery.uploadifive.js"></script>
<script type="text/javascript">
    $(function(){
        $('input[data-action]').click(function(){
            $action = $(this).data('action');
            if ($action == 'save') {
                var pwd1 = $('#pwd1'), pwd2 = $('#pwd2'), role_id = $('#role_id').val(), status = $('#status').val();
                if (pwd1.val() != '' && pwd1.val() != pwd2.val()) {
                    layer.msg('再次输入的密码不一致', {icon: 5, time: 1000}, function(){pwd1.focus()});
                    return false
                }
                if (role_id <= 0) {
                    layer.msg('请选择用户角色', {icon: 5, time: 1000});
                    return false
                }
                $.ajax({
                    type: 'post', cache: false, dataType: 'json',
                    url: '{:url("edit")}',
                    data: {'id': {$user.id}, 'username': $('#username').val(), 'password': pwd2.val(), 'role_id': role_id, 'status': status},
                    success: function(data){
                        if (data.status == 0) {
                            layer.msg(data.info, {icon: 6, time: 1000});
                        }else if (data.status == 88) {
                            layer.msg(data.info, {icon: 6, time: 1000}, function(){
                                window.top.location.href = '/71a4d6e847b6214b/login?action=logout'
                            })
                        }else{
                            layer.msg(data.info, {icon: 5, time: 1000});
                        }
                    }
                });
            }{if($uname==='admin'||$uname==='royhe')} else if ($action == 'cancel') {
                location.href = '{:url("lists")}';
            }{/if}
        });
    });
</script>
</html>